package com.msf.modules.sys.domain.vo;

import com.msf.modules.sys.entity.SysPermission;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class MenuOption {

    /**
     * @description 路由参数配置简介
     * path ==> 路由菜单访问路径
     * name ==> 路由 name (对应页面组件 name, 可用作 KeepAlive 缓存标识 && 按钮权限筛选)
     * redirect ==> 路由重定向地址
     * component ==> 视图文件路径
     * meta ==> 路由菜单元信息
     * meta.icon ==> 菜单和面包屑对应的图标
     * meta.title ==> 路由标题 (用作 document.title || 菜单的名称)
     * meta.activeMenu ==> 当前路由为详情页时，需要高亮的菜单
     * meta.isLink ==> 路由外链时填写的访问地址
     * meta.isHide ==> 是否在菜单中隐藏 (通常列表详情页需要隐藏)
     * meta.isFull ==> 菜单是否全屏 (示例：数据大屏页面)
     * meta.isAffix ==> 菜单是否固定在标签页中 (首页通常是固定项)
     * meta.isKeepAlive ==> 当前路由是否缓存
     * */

    private String id;
    private String parentId;
    private String key;
    private String path;
    private String name;
    private Integer menuType;
    private String icon;
    private String component;
    private String componentName;
    private String redirect;
    private Double sortNo;
    private boolean isLeaf;
    private MetaProp meta;
    private List<MenuOption> children;

    public boolean getIsLeaf() {
        return isLeaf;
    }

    public MenuOption(SysPermission permission) {
        this.id = permission.getId();
        this.parentId = permission.getParentId();
        this.key = permission.getId();
        this.path = permission.getPath();
        this.name = permission.getName();
        this.menuType = permission.getMenuType();
        this.icon = permission.getIcon();
        this.component = permission.getComponent();
        this.componentName = permission.getComponentName();
        this.redirect = permission.getRedirect();
        this.sortNo = permission.getSortNo();
        this.isLeaf = permission.isLeaf();
        this.meta = new MetaProp(permission);
        if (!permission.isLeaf()) {
            this.children = new ArrayList<>();
        }
    }

}
